#include <assert.h>

#include "File.h"

File::File(const std::string & fileName, int modes) : sFileName(""), bIsOpened(false)  
{
	if(false == fileName.empty())
		Open(fileName, modes);
};

File::File(const File&)
{
	/* need Dup function! */
};

File& File::operator=(const File&)
{
	/* need Dup function */
	return *this;
};

File::~File()
{
	while(IsOpened())
		Close();
};


bool File::IsOpened() const
{
	return bIsOpened;
};

const std::string & File::GetFileName() const
{
	return sFileName;
};
	
bool File::Open(const std::string & fileName, int modes)
{
	assert(false == bIsOpened);
	sFileName = fileName;
	bIsOpened = ::Open(&fHandle, sFileName.c_str(), modes);
	return bIsOpened;
};

bool File::Close()
{
	if(bIsOpened)
	{
		::Close(&fHandle);
		bIsOpened = false; 
	};
	return bIsOpened;
};
	
SSizeType File::Read(void * data, SizeType nbytes) const
{
	return ::Read(&fHandle, data, nbytes);
};

SSizeType File::Write(const void * data, SizeType nbytes)
{
	return ::Write(&fHandle, data, nbytes);
};
	
SSizeType File::PRead(void * data, SizeType nbytes, SizeType offset) const
{
	return ::PRead(&fHandle, data, nbytes, offset);
};

SSizeType File::PWrite(const void * data, SizeType nbytes, SizeType offset)
{
	return ::PWrite(&fHandle, data, nbytes, offset);
};

SizeType File::Seek(SizeType offset, int whence)
{
	return ::Seek(&fHandle, offset, whence);
};

bool File::Truncate(SizeType iNewSize)
{
	return ::Truncate(&fHandle, iNewSize);
};


